#pragma once
#include "schematic_types.h"
#include <pybind11/pybind11.h>
#include <pybind11/eval.h>
#include <pybind11/embed.h>
#include <string>
#include <vector>
#include <memory>
#include <filesystem>

namespace drc {

class DRCViolation {
public:
    std::string rule_name;
    std::string message;
    std::string severity;  // "error", "warning", "info"
    schematic::Component component;  // 改为值类型
    schematic::Net net;             // 改为值类型
};

class DRCRule {
public:
    virtual ~DRCRule() = default;
    virtual std::vector<DRCViolation> check(const schematic::Schematic& schematic) = 0;
};

class PythonRule : public DRCRule {
public:
    PythonRule(const std::string& rule_file);
    std::vector<DRCViolation> check(const schematic::Schematic& schematic) override;
    std::string rule_name;

private:
    pybind11::module_ rule_module;
};

class DRCManager {
public:
    DRCManager();
    ~DRCManager();  // 添加析构函数声明
    
    // 加载Python规则文件
    void load_rule(const std::string& rule_file);
    
    // 加载规则目录下的所有规则
    void load_rules_from_directory(const std::string& directory);
    
    // 运行所有规则检查
    std::vector<DRCViolation> run_all_checks(const schematic::Schematic& schematic);
    
    // 运行指定规则检查
    std::vector<DRCViolation> run_rule(const std::string& rule_name, 
                                      const schematic::Schematic& schematic);

private:
    std::vector<std::unique_ptr<DRCRule>> rules;
    pybind11::scoped_interpreter guard;  // Python解释器
};

} // namespace drc 